package com.baseproject.widget.refresh;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.baseproject.R;


/**
 * @version V1.0  2017/3/28下午8:10
 * @author:OliverTan(www.tandunzhao.cn)
 */
class ZwRefreshView extends FrameLayout implements IHeaderView {
  private ImageView loadingView;

  public ZwRefreshView(Context context) {
    this(context, null);
  }

  public ZwRefreshView(Context context, AttributeSet attrs) {
    this(context, attrs, 0);
  }

  public ZwRefreshView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init();
  }

  private void init() {
    View rootView = View.inflate(getContext(), R.layout.refresh, null);
    loadingView = (ImageView) rootView.findViewById(R.id.iv_loading);
    addView(rootView);
  }

  @Override
  public View getView() {
    return this;
  }

  @Override
  public void onPullingDown(float fraction, float maxHeadHeight, float headHeight) {
  }

  @Override
  public void onPullReleasing(float fraction, float maxHeadHeight, float headHeight) {
  }

  @Override
  public void startAnim(float maxHeadHeight, float headHeight) {
    loadingView.setVisibility(VISIBLE);
    ((AnimationDrawable) loadingView.getDrawable()).start();
  }

  @Override
  public void onFinish(OnAnimEndListener animEndListener) {
    animEndListener.onAnimEnd();
  }

  @Override
  public void reset() {
  }
}
